package com.study.annotation;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class SpringAnnotationTest {

    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(MainConfig.class);

        Person bean = context.getBean(Person.class);

        String[] beanDefinitionNames = context.getBeanDefinitionNames();

        for (String name : beanDefinitionNames) {
            System.out.println("className==============" + name);
        }
        System.out.println(bean);
    }
    @Test
    public void test(){

        ApplicationContext context  = new AnnotationConfigApplicationContext(MainConfig2.class);

        String[] beanDefinitionNames = context.getBeanDefinitionNames();

        for (String name : beanDefinitionNames) {
            System.out.println("className==============" + name);
        }

    }


    @Test
    public void test1(){

        ApplicationContext context  = new AnnotationConfigApplicationContext(MainConfig3.class);

        String[] beanDefinitionNames = context.getBeanDefinitionNames();

        for (String name : beanDefinitionNames) {
            System.out.println("className==============" + name);
        }

    }

    @Test
    public void testImport(){

        ApplicationContext context  = new AnnotationConfigApplicationContext(MainConfigImport.class);

        String[] beanDefinitionNames = context.getBeanDefinitionNames();

        for (String name : beanDefinitionNames) {
            System.out.println("className==============" + name);
        }

    }

    @Test
    public void factoryBeanTest(){
        AnnotationConfigApplicationContext annotationConfigApplicationContext =  new AnnotationConfigApplicationContext(MainConfigFactory.class);
        String[] beanDefinitionNames = annotationConfigApplicationContext.getBeanDefinitionNames();

        for (String name : beanDefinitionNames) {
            System.out.println("className==============" + name);
        }
        Class<?> beanFactory = annotationConfigApplicationContext.getBean("beanFactory").getClass();
        System.out.println("--------->" + beanFactory.getName());


    }





}
